

use "$path\Intermediary Data\localshock_dataforReg_v2.dta",clear

drop if prix_ht==.
drop  j j3
replace d_dieselr=resid_movav_diesel
xtset id daten
gen d_dieselrott=ln(diesel_rotterdam_euro)-ln(l1.diesel_rotterdam_euro)
drop diesel_rotterdam_euro resid_movav_diesel dprix1 

drop d_dieselr
gen d_dieselr=d_dieselrott

merge m:m id using  "$path\Intermediary Data\base_id_suff_stat_6Y"
keep if _m==3
drop _m

merge m:m id using  "$path\Intermediary Data\base_base_suff_stat_6Y_forinteractkurtfreq"
keep if _m==3
drop _m




**** 
capture drop ratio
gen ratio=kurtosis/freq

drop num_obs
gen num_obs=_n-1

capture drop local_shock5 local_shock15 local_shock4 local_shock6 local_shock7 local_shock8
capture drop coeff1_reg
capture drop coeff2_reg
capture drop coeff_c_reg
capture drop se_coeff1_reg
capture drop se_coeff2_reg
capture drop df_reg


gen coeff1_reg=.
gen coeff2_reg=.
gen coeff_c_reg=.
gen se_coeff1_reg=.
gen se_coeff2_reg=.
gen df_reg=.


capture drop f_prix_ht f_prix_ht_temp
gen f_prix_ht=0


foreach i of numlist 1/30 {
 
bysort id (daten):  gen f_prix_ht_temp=(log(prix_ht[_n+`i'])-log(prix_ht[_n-1]))/lt_effect
replace f_prix_ht=f_prix_ht_temp+f_prix_ht


areg f_prix_ht c.d_dieselr##c.ratio c.local_shock10##c.ratio c.m_dprix##c.ratio c.l.d_dieselr##c.ratio c.l2.d_dieselr##c.ratio c.l3.d_dieselr##c.ratio c.l4.d_dieselr##c.ratio ///
c.l5.d_dieselr##c.ratio ///
		c.l.local_shock10##c.ratio c.l2.local_shock10##c.ratio c.l3.local_shock10##c.ratio c.l4.local_shock10##c.ratio c.l5.local_shock10##c.ratio ///
	c.l.m_dprix##c.ratio  c.l2.m_dprix##c.ratio c.l3.m_dprix##c.ratio c.l4.m_dprix##c.ratio c.l5.m_dprix##c.ratio, absorb(id) vce(cluster daten)

	

	
matrix test=r(table)
replace coeff1_reg=_b[d_dieselr] if num_obs==`i'
replace coeff2_reg=_b[c.d_dieselr#c.ratio] if num_obs==`i'
replace coeff_c_reg=_b[_cons] if num_obs==`i'


replace se_coeff1_reg=_se[d_dieselr] if num_obs==`i'
replace se_coeff2_reg=_se[c.d_dieselr#c.ratio] if num_obs==`i'
replace df_reg=e(df_r) if num_obs==`i'
capture drop  f_prix_ht_temp
di "Numéro itération :" `i'
}


preserve
keep coeff1_reg coeff2_reg coeff_c_reg  se_coeff1_reg se_coeff2_reg df_reg num_obs
gen name="BASELINE - interaction kurt freq"
gen charact="LAGS, STANDARD SHOCK, STATION FE, DATE CLUSTER"
keep if num_obs<=40
save "$path\Graphs_Tables\Data_Figure7a.dta", replace
restore





use "$path\Graphs_Tables\Data_Figure7a.dta", clear

gen ci_coeff1_m=coeff1_reg-1.96*se_coeff1_reg
gen ci_coeff1_p=coeff1_reg+1.96*se_coeff1_reg
gen ci_coeff2_m=coeff2_reg-1.96*se_coeff2_reg
gen ci_coeff2_p=coeff2_reg+1.96*se_coeff2_reg

local nj=30
gen h=num_obs
sort h
graph twoway (rarea  ci_coeff1_m ci_coeff1_p h if h<=`nj', col(grey%10)) ///
(line  coeff1_reg h if h<=`nj', col(black) ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') ylabel(0(5)30) 

graph export "$path\Graphs_Tables\Figure7a_1.png", replace
graph export "$path\Graphs_Tables\Figure7a_1.eps", replace

local nj=30
sort h
graph twoway (rarea  ci_coeff2_m ci_coeff2_p h if h<=`nj', col(grey%10)) ///
(line  coeff2_reg h if h<=`nj', col(black)  ///
legend(off) graphregion(color(white)) xtitle("Time (in days)") ytitle("Cum. Response")) ///
, xlabel(0(2)`nj') 

graph export "$path\Graphs_Tables\Figure7a_2.png", replace
graph export "$path\Graphs_Tables\Figure7a_2.eps", replace




